#include<stdio.h>

int main()
{
    int arr[] = {1,2,3,4,5,6,7,8,9,10};
    int left = 0;
    int right = sizeof(arr) / sizeof(arr[0]) - 1;

    printf("请输入一个10以内的整数：");
    int key = 0;//要找的数字
    scanf("%d",&key);

    int mid = 0;//二分法，中间数字很重要。
    int found = 0;

    while (left <= right)
    {
        mid = left + (right - left) / 2;
        if(arr[mid] < key){
            left = mid + 1;
        }
        else if(arr[mid] > key){
            right = mid - 1;
        }

        else
        {
            found = 1;
            break;
        }
    }

    if(found){
        printf("找到了，下标是%d\n",mid);
    }
    else{
        printf("找不到～");
    }

    return 0;
}